
% tai2brk
% Chris Whalen
% University of Illinois
% 05/20/04

% tai2brk - this program takes the tai structure and converts to brk coords

function [tai_fid, tai_origin] = tai2brk(tai)


i_Na = 9; i_LPA=10; i_RPA=11;  % "should be" L=10, R=11
nx = 191;

% permute .tai coords to .BRIK order
temp(1)=tai.scale(2);
temp(2)=tai.scale(1);
temp(3)=tai.scale(3);
tai.scale=temp;
%
for i_tai=1:size(tai.xyz,1)
 temp(1)=nx - tai.xyz(i_tai,2);  % 2, nx- for OLD .tais ? 
 temp(2)=tai.xyz(i_tai,1);  % 1
 temp(3)=tai.xyz(i_tai,3);  % 3
 tai.xyz(i_tai,:)=temp;
end

tai_origin= round((tai.xyz(i_LPA,:)+tai.xyz(i_RPA,:))/2); % .tai-.elp origin offset = (LPA+RPA)/2

for i=i_Na:i_RPA
    tai_fid(i + 1 - i_Na,:) = tai.xyz(i,:);
end
% Place in TAI origin w/Brik ref frame
for i=1:3
    tai_fid(i,:) = tai_fid(i,:) - tai_origin(1,:);  % place in TAI coords
end







